/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ca.barrenechea.stickyheaders.view;

import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.window.dialog.PopupDialog;
import ohos.app.Context;

import ca.barrenechea.stickyheaders.ResourceTable;

/**
 * 自定义弹框
 *
 * @since 2021-04-27
 */
public class CustomDialog extends PopupDialog {
    private Button btnClear;
    private Button btnAbout;
    private PopDestroyedListener mPopDestroyedListener;

    /**
     * 构造函数
     *
     * @param context 上下文
     * @param contentComponent 显示在某控件周围
     */
    public CustomDialog(Context context, Component contentComponent) {
        super(context, contentComponent);
        Component rootView = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_dialog_menu, null, true);
        btnClear = (Button) rootView.findComponentById(ResourceTable.Id_text_clear);
        btnAbout = (Button) rootView.findComponentById(ResourceTable.Id_text_about);
        setCustomComponent(rootView);
    }

    /**
     * 设置Clear按钮点击监听
     *
     * @param clickedListener
     */
    public void setBtnClearClickedListener(Component.ClickedListener clickedListener) {
        btnClear.setClickedListener(clickedListener);
    }

    /**
     * 设置About按钮点击监听
     *
     * @param clickedListener
     */
    public void setBtnAboutClickedListener(Component.ClickedListener clickedListener) {
        btnAbout.setClickedListener(clickedListener);
    }

    /**
     * 销毁弹框
     */
    protected void onDestroy() {
        super.onDestroy();
        if (mPopDestroyedListener != null) {
            mPopDestroyedListener.onPopDestroy();
        }
    }

    /**
     * 自定义销毁监听接口
     *
     * @since 2021-04-27
     */
    public interface PopDestroyedListener {
        /**
         * 弹框已销毁回调
         */
        void onPopDestroy();
    }
}
